//字典解析
  dictdata['area'] = AreaListData;
//点击切换分类
var mes = $('#main p').last().find('span.selected').attr("val");//项目类型
var today = $('#main p').attr("today");
var message = $('#main p').last().attr("message");
var notic = $('#list ul li div.notice');
var clo;
var text="";
var name;
var href;
var cli,sheng,shi,xian;
//公告类型选择
$('#main p ').first().find("input").click(function(){
   $('#main p').first().find("span").removeClass("selected");
   $(this).prev('span').addClass("selected");
   $('#sh').click();
});
$('#main p ').last().find("input").click(function(){
   $('#main p').last().find("span").removeClass("selected");
   $(this).prev('span').addClass("selected");
   $('#sh').click();
})

if(text=="0"){
    $('#list').hide();
    $('#empty').show();
}
//切换结果页后隐藏快捷报价和截至时间
if(message == 1){
    kuaijie.hide();
    jiezhi.hide();
}
//省市县
$.each(AreaListData, function (k, v) {
    if (v[1] == 0) {
        var option = "<option value='" + k + "'>" + v[0] + "</option>";
        $('#province').append(option);
    }
});
$('#province').change(function () {
    $('#city option:gt(0)').remove();
    $('#district option:gt(0)').remove();
    var sheng = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == sheng) {
            var option = "<option value='" + k + "'>" + v[0] + "</option>";
            $('#city').append(option);
        }
    });
});
$('#city').change(function () {
    $('#district option:gt(0)').remove();
    var shi = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == shi) {
            var option = "<option value='" + k + "'>" + v[0] + "</option>";
            $('#district').append(option);
        }
    });
});
function changeURLArg(url,arg,arg_val){ 
    var pattern=arg+'=([^&]*)'; 
    var replaceText=arg+'='+arg_val; 
    if(url.match(pattern)){ 
        var tmp='/('+ arg+'=)([^&]*)/gi'; 
        tmp=url.replace(eval(tmp),replaceText); 
        return tmp; 
    }else{ 
        if(url.match('[\?]')){ 
            return url+'&'+replaceText; 
        }else{ 
            return url+'?'+replaceText; 
        } 
    } 
    return url+'\n'+arg+'\n'+arg_val; 
}
function getNum(text){
var value = text.replace(/[^0-9]/ig,"");
return value;
}

$('button').click(function(){
    fengzi.text("1");
    query(1);
    num();
});
var fengzi = $('#page_navigation a b').first();
var fengmu = $('#page_navigation a b').last();
var h = $('#list ul');
var typ,shijian,enddt,hide;
//首页
    function first(){
        query(1);
        fengzi.text("1");
    }
//上一页    
    function previous(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi>1){
        zi= zi-1;
        fengzi.text(zi);
        query(zi);
        }
    }
//下一页    
    function next(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi<mu){
        zi= zi+1;
        fengzi.text(zi);
        query(zi);
        }
    }
//尾页    
    function last(){
        query(fengmu.text());
        fengzi.text(fengmu.text());
    }
    //跳转
  function jump(){
   var jump = $('[name=jump]').val();
   var mu = parseInt(fengmu.text());
   if(1<=jump&&jump<=mu){
        fengzi.text(jump);
        query(jump);
   }
  } 
function query(page){
    h.empty();
    text="";
    new Ajax("/search_result_query.jsp").keyvalue($('#form').serializeArray()).keyvalue("page",page).getJson(function(json){
        $.each(json,function(key,val){
            if(val["typid"]==1){
                clo ="#ffb800";
                name ="采购";
                href ="/purchase/details/";
                cli ="快捷报价";
                hide ="show";
            }
          if(val["state"]==2){
                clo ="#009688";
                name ="完成";
                hide ="none";
                href="/purchase/result/"
            }
            if(val["state"]==3){
                clo ="red";
                name ="流标";
                hide ="none";
                href="/purchase/result/"
            }
//           sheng = AreaListData[val["shengid"]][0];
//           shi = AreaListData[val["shiid"]][0];
//           xian = AreaListData[val["xianid"]][0];
           shijian = new Date(val["shijian"]*1000).toString().substring(0,10);
           enddt = new Date(val["enddt"]*1000).toString().substring(0,10);
           text +="<li><div class='notic' style='background-color:"+clo+"'>"+name+"</div><a class='name' href='"+href+""+val["id"]+"' target='blank'>"+val["name"]+"</a><h2>发布企业：<a class='company' href='#' target='blank'>"+val["corpname"]+"</a></h2><h3>所在地：<span class='addr'>"+val["fulladress"]+"</span></h3><h4>截至日期：<span>"+enddt+"</span></h4><h5>发布时间：<span>"+shijian+"</sapn></h5><a style='display:"+hide+"' class='price' href='"+href+""+val["id"]+"' target='blank'>"+cli+"</a></li>";
        })
         h.html(text);
    });

};
function num(){
    new Ajax("/search_results_page.jsp").keyvalue($('#form').serializeArray()).get(function(json){
         $('#num').text("共有"+json+"条");
         if(json==0){
             $('#empty').show();
             $('#page_navigation').hide();
         }else{
              $('#empty').hide();
              $('#page_navigation').show();
         }
         numb = Math.ceil(json.replace(/[^0-9]/ig, "")/10);
         fengmu.text(numb);
         
    })
}